import axios from 'axios'
import { Toast } from 'vant';
import router from '../router'
axios.defaults.withCredentials = true

axios.interceptors.response.use((res) => {
    console.log(res.data.code)
    if (res.data.code == 901 || res.data.code == 999) {

        localStorage.removeItem("customerwx");
        localStorage.removeItem("wechataccess_user_token");
        localStorage.removeItem("mobileInfo");
        router.replace('/login')
    }
    return res;
}, (error) => {
    return Promise.reject(error);
});
axios.interceptors.request.use(
    config => {
        const token = localStorage.getItem("customerwx");
        token && (config.headers.mlfastsessionid = token);
        return config;
    },
    error => {
        return Promise.error(error);
    }
);
export function fetchPost(url, params = {}) {
    return axios({
        method: "POST",
        url: url,
        data: params,
    })
};
export function fetchGet(url, param) {
    return new Promise((resolve, reject) => {
        axios.get(url, { params: param })
            .then(response => {
                resolve(response)
            }, err => {
                reject(err)
            })
            .catch((error) => {
                reject(error)
            })
    })
}